package com.coin900.coin.service.coin;

import com.coin900.coin.base.CoinConstants;
import com.coin900.coin.persist.coin.CoinCoinVO;
import com.coin900.coin.persist.coin.CoinTokenVO;
import com.value.mybatis.IDaoRouter;
import com.value.mybatis.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 代币
 *
 * @author shui
 * @create 2018-1-14
 */
@Service
public class CoinTokenService implements ICoinTokenService {

    @Override
    public List<CoinTokenVO> loadCoinToken(Map<String, Object> params) {
        return this.daoRouter.query("CoinToken.loadCoinToken", params);
    }

    @Override
    public List<CoinTokenVO> loadCoinTokenForPage(Pagination pagination) {
        return this.daoRouter.query("CoinToken.loadCoinTokenForPage", pagination);
    }

    @Override
    public void insertCoinToken(CoinTokenVO coinTokenVO) {
        CoinCoinVO coinCoinVO = new CoinCoinVO();
        coinCoinVO.setType(CoinConstants.COIN_TYPE_TOKEN);
        coinCoinVO.setAccuracy(coinTokenVO.getAccuracy());
        coinCoinVO.setCoinName(coinTokenVO.getShortName().toLowerCase());
        coinCoinVO.setPayforTokenStatus(0);
        coinCoinVO.setReleaseStatus(0);
        coinCoinVO.setShowInWalletStatus(0);
        coinCoinVO.setCreatedBy(coinTokenVO.getModifiedBy());
        coinCoinVO.setCreatedDate(coinTokenVO.getModifiedDate());
        coinCoinVO.setDataStatus(1);
        this.coinCoinService.insertCoinCoin(coinCoinVO);
        coinTokenVO.setCoinId(coinCoinVO.getId());
        this.daoRouter.insert("CoinToken.insertCoinToken", coinTokenVO);
    }

    @Override
    public void updateCoinToken(CoinTokenVO coinTokenVO) {
        CoinCoinVO coinCoinVO = new CoinCoinVO();
        coinCoinVO.setId(coinTokenVO.getCoinId());
        coinCoinVO.setCoinName(coinTokenVO.getCoinName());
        this.coinCoinService.updateCoinCoin(coinCoinVO);
        this.daoRouter.update("CoinToken.updateCoinToken", coinTokenVO);
    }

    @Override
    public void deleteCoinToken(CoinTokenVO coinTokenVO) {
        this.daoRouter.update("CoinToken.deleteCoinToken", coinTokenVO);
        CoinCoinVO coinCoinVO = new CoinCoinVO();
        coinCoinVO.setType(CoinConstants.COIN_TYPE_TOKEN);
        coinCoinVO.setModifiedDate(coinTokenVO.getModifiedDate());
        coinCoinVO.setModifiedBy(coinTokenVO.getModifiedBy());
        coinCoinVO.setDataStatus(0);
        this.coinCoinService.deleteCoinCoin(coinCoinVO);
    }

    @Autowired
    private ICoinCoinService coinCoinService;
    @Autowired
    private IDaoRouter daoRouter;

}